package com.osi.mes.qm.services;

import java.util.Vector;

import pnuts.lang.Context;

import com.datasweep.compatibility.client.ATHandler;
import com.datasweep.compatibility.client.ATRow;
import com.datasweep.compatibility.client.ATRowFilter;
import com.datasweep.compatibility.client.DatasweepException;
import com.datasweep.compatibility.client.Route;
import com.datasweep.compatibility.client.Step;
import com.osi.mes.base.BaseService;
import com.osi.mes.qm.base.constants.IATNames;
import com.osi.mes.utils.StringUtils;

public class QmForeignMatterService extends BaseService {

	public QmForeignMatterService(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	// 根据异物类型大类找小类
	public Vector<String> getFMTypeFromClassication(String fmBigType)
			throws DatasweepException {
		Vector<String> rets = new Vector<String>();
		String atDefName = IATNames.AT_FOREIGN_MATTER_TYPE;
		ATHandler atHandler = getFunctions().createATHandler(atDefName);
		ATRowFilter rowFilter = getFunctions().createATRowFilter(atDefName);
		if (!StringUtils.isNull(fmBigType))
			rowFilter.forColumnNameEqualTo(IATNames.FOREIGN_MATTER_BIG_TYPE,
					fmBigType);
		Vector<ATRow> fmTypeResults = atHandler.getATRowsByFilter(rowFilter,
				false);
		if (fmTypeResults == null || fmTypeResults.size() == 0)
			return rets;

		for (int i = 0; i < fmTypeResults.size(); i++) {
			ATRow atRow = fmTypeResults.get(i);
			String fmSmallType = (String) atRow
					.getValue(IATNames.FOREIGN_MATTER_TYPE);
			if (!rets.contains(fmSmallType))
				rets.add(fmSmallType);
		}

		return rets;
	}

	// 获得所有的route
	public Vector<Step> getRouteStepFormRoute(Route route)
			throws DatasweepException {
		Vector<Step> allRouteSteps = new Vector<Step>();

		if (route == null)
			return allRouteSteps;

		return route.getSteps();
	}

}
